﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BlueCMS.Core.Helpers;
using BlueCMS.Core.Pages;

using BlueCMS.Core.Data.Query;

namespace BlueCMS.Core.Entities
{
    public class Template
    {
        public Guid template_id { get; set; }
        public Guid website_id { get; set; }
        public string template_nm { get; set; }
        public string layout { get; set; }
        public bool isactive { get; set; }
        public bool isdeleted { get; set; }

        public IEnumerable<TemplateFragment> Fragments { get; set; }

        public IList<PageletInstance> GetPageletsForRegion(string region)
        {
            // TODO: Security trim the results - each PageletInstance should have a Node with security attached
            return null;//TEMP: return DataProvider().GetPageletInstances().Where(pi => pi.TemplateId == TemplateId && pi.Region == region).OrderBy(pi => pi.DisplayOrder).ToList();
        }

        //protected override void BeforeSave()
        //{
        //    //DeleteQuery query = new DeleteQuery();
        //    //query.Delete.Table("cms_templatefragment_tbl");
        //    //query.Where.Equals("template_id", new Constant(id));
        //    //DataAccess.Instance.ExecuteNonQuery(query.Sql);

        //    //Fragments = TemplateParser.Parse(layout, this);
        //    //foreach (TemplateFragment fragment in Fragments)
        //    //{
        //    //    fragment.Save();
        //    //    fragment.Template = this;
        //    //}
        //}

        //public void Save()
        //{
        //TEMP: DataProvider().DeleteTemplateFragments(TemplateId);
        //TEMP: DataProvider().SaveTemplateFragments(TemplateParser.Parse(Layout, this));

        //TEMP: DataProvider().SaveTemplate(this);
        //}
    }
}
